package com.ww.hegou.util;

import com.ww.hegou.HegouApplication;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.stereotype.Component;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;

@Slf4j
@Component

public class OkHttpUtil {
    public void post(IOkHttp iOkHttp,RequestBody requestBody,Request request ){

        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.newCall(request).enqueue(new Callback() {
            public void onFailure(Call call, IOException e) {
                log.info("请求失败");
            }

            public void onResponse(Call call, Response response) throws IOException {
                iOkHttp.onResponse(call,response);
            }
        });

    }

    public void get(IOkHttp iOkHttp,Request request ){

        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.newCall(request).enqueue(new Callback() {
            public void onFailure(Call call, IOException e) {
                log.info("请求失败");
            }

            public void onResponse(Call call, Response response) throws IOException {
                iOkHttp.onResponse(call,response);
            }
        });

    }
}
